﻿<?php
require_once('../db/check_login.php');
require_once('../db/config.php');
$db=new db($config);
$user=$db->foundbyWhere('user');
foreach($user as $key=>$val){
$userRole=$db->foundOnebyWhere('user_role',"u_id='$val[id]'"); 
$roleName=$db->foundOnebyWhere('role',"id='$userRole[r_id]'"); 
$user[$key]['role_name']=$roleName['name'];          
}
/*foreach($user as $keys=>$val){
$result = array();	
$row =$db->foundbyWhere('user_role',"u_id='$val[id]'");
foreach ($row as $key => $value) {
$result[$key] = $value['r_id'];
}
$res=array();
foreach ($result as $k=>$v){
$row=$db->foundbyId('role', $v);	
$res[$k]=$row['name'];
}
$user[$keys]['role'] = $res;
}
<?php foreach($value['role'] as $val): ?> 
<?php echo $val ?>
<?php endforeach;?>
*/
?>
<p><a href="add.php">添加用户</a></p>
<table width="100%" border="0">
  <tr>
    <td width="12%" align="center">用户名</td>
    <td width="32%" align="center">职位</td>
    <td width="56%" align="center">操作</td>
  </tr>
  <?php if(!empty($user)&&is_array($user)):?>
  <?php foreach($user as $value): ?> 
  <tr>
    <td align="center"><?php echo $value['user']?></td>
 
    <td align="center">
   <?php echo $value['role_name']?>
    </td>
    <td align="center">修改/删除</td>
  </tr>
  <?php endforeach;?>
  <?php else :?>
  <td align="center">暂无记录</td>
  <?php endif;?>
</table>

